#ifndef TC_OPTIONS_HH
#define TC_OPTIONS_HH

/** \file Options.hh 
 * Get command line options.
 *
 * (c) Copyright by Semih Cemiloglu
 * All rights reserved, see COPYRIGHT file for details.
 *
 * $Id: SmIf.hh 119 2006-06-21 04:57:25Z semihc $
 *
 *
 */

#include <QString>
#include <QStringList>
#include <QRegExp>
#include <QMap>
#include <QList>
#include "Global.hh"

// FORWARDS
class QTextStream;


namespace TC {

struct Option {
  // MEMBERS
  QString m_name;
  QChar m_letter;
  QRegExp m_regex;
  QString m_desc;
  QString m_def; // default value

  // CREATORS
  Option() {}
  Option(QString name, QChar letter, QRegExp regex, QString desc)
      : m_name(name), m_letter(letter), m_regex(regex), m_desc(desc) {}

  // MODIFIERS
  Option& name(QString n) { m_name = n; return *this; }
  Option& letter(QChar l) { m_letter = l; return *this; }
  Option& regex(QString r) { m_regex = QRegExp(r); return *this; }
  Option& desc(QString d) { m_desc = d; return *this; }
  Option& def(QString d) { m_def = d; return *this; }
};


class Options : public QObject
{
  Q_OBJECT
  
 public:
  // TYPES
  //! Option specifications
  typedef QList<Option> OptionSpecs_t;
  //! Option values
  typedef QMap<QString, QString> OptionVals_t;

  // CREATORS
  Options() {}
  Options(int argc, const char** argv);
	Options(QStringList args);
	virtual ~Options();  

  // MODIFIERS
  Options& addOption(const Option& opt);
  
  Options& operator+=(const Option& opt)
  { return addOption(opt); }

  OptionSpecs_t& getOptionSpecs() 
  { return m_optSpecs; }

  OptionVals_t& getOptionVals()
  { return m_optVals; }

  void clear();

 public slots:
	void printUsage(QTextStream& out);
  void setArgs(QStringList args);
	bool parse();	

  private:
  // MEMBERS
  QStringList m_args;
  OptionSpecs_t m_optSpecs;
  OptionVals_t m_optVals;
  
}; // end class

} // end namespace


#endif // include guard
